from django.contrib import admin
from .models import Review

@admin.register(Review)
class ReviewAdmin(admin.ModelAdmin):
    list_display = ['id', 'type', 'status', 'user', 'vehicle', 'submitted_at', 'reviewed_at']
    list_filter = ['type', 'status', 'submitted_at', 'reviewed_at']
    search_fields = ['user__phone', 'vehicle__license_plate']
    readonly_fields = ['submitted_at', 'reviewed_at']
    
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        # 管理员可以看到所有审核记录
        if request.user.is_staff:
            return qs
        # 普通用户只能看到自己的审核记录
        return qs.filter(user=request.user)